﻿using System.Collections.ObjectModel;


namespace LayoutViewer.Models
{
    public class Bounds
    {
        public int Left { get; set; } = 0;
        public int Top { get; set; } = 0;
        public int Right { get; set; } = 0;
        public int Bottom { get; set; } = 0;

        public override string ToString()
        {
            var result = $"{this.Left},{this.Top},{this.Right},{this.Bottom}";
            return result;
        }

        public static Bounds Parse(string bounds)
        {
            var arr = bounds.Replace("][", ",").Replace("[", "").Replace("]", "").Replace(" ", "").Split(",");

            var result = new Bounds
            {
                Left = int.Parse(arr[0]),
                Top = int.Parse(arr[1]),
                Right = int.Parse(arr[2]),
                Bottom = int.Parse(arr[3])
            };

            return result;
        }
    }
    public class MoveCategory
    {
        public bool? AccessibilityFocused { get; set; }
        public Bounds? Bounds { get; set; }
        public bool? Checkable { get; set; }
        public bool? Checked { get; set; }
        public string? ClassName { get; set; }
        public bool? Clickable { get; set; }
        public int? Column { get; set; }
        public int? ColumnCount { get; set; }
        public int? ColumnSpan { get; set; }
        public bool? ContextClickable { get; set; }
        public int? Depth { get; set; }
        public string? Desc { get; set; }
        public bool? Dismissable { get; set; }
        public int? DrawingOrder { get; set; }
        public bool? Editable { get; set; }
        public bool? Enabled { get; set; }
        public bool? Focused { get; set; }
        public int? IndexInParent { get; set; }

        private string? id;
        public string? Id
        {
            get => this.id;
            set
            {
                this.id = value?[(value.LastIndexOf("/") + 1)..];
            }
        }
        public bool? LongClickable { get; set; }
        public string? PackageName { get; set; }
        public int? Row { get; set; }
        public int? RowCount { get; set; }
        public int? RowSpan { get; set; }
        public bool? Scrollable { get; set; }
        public bool? Selected { get; set; }
        public string? Text { get; set; }
        public bool? VisibleToUser { get; set; }
        public string Title
        {
            get
            {
                if (this.Id == null)
                {
                    return $"{ this.ClassName?[(this.ClassName.LastIndexOf(".") + 1)..] }";
                }
                return $"{ this.ClassName?[(this.ClassName.LastIndexOf(".") + 1)..] }  [id: { this.Id }]";

            }
        }
        public ObservableCollection<MoveCategory>? Children { get; set; }

        //public MoveCategory(int hwnd, string title, string className, params MoveCategory[] children)
        //{
        //    //Hwnd = hwnd;
        //    //Title = title;
        //    //ClassName = className;
        //    //Info = string.Format("[{0}][{1}][{2}]", hwnd, title, className);
        //    //Moves = new ObservableCollection<MoveCategory>(movies);
        //}
    }
}
